package com.smart.controller;

import com.smart.common.PageInfo;
import com.smart.common.WebResponse;
import com.smart.common.annotation.WebAccess;
import com.smart.model.request.SuperviseUserAddRequest;
import com.smart.model.request.SuperviseUserRequest;
import com.smart.model.request.SuperviseUserUpdateRequest;
import com.smart.model.vo.SuperviseUserVO;
import com.smart.service.SuperviseUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author zhanghong
 */
@RestController
@RequestMapping("/superviseUser")
@Api(value = "云监管平台#账户管理模块", tags = "云监管平台#账户管理模块")
public class SuperviseUserController {

    @Autowired
    private SuperviseUserService superviseUserService;

    @WebAccess(login = true)
    @ApiOperation("分页查询")
    @PostMapping("/pageQuery")
    public WebResponse<PageInfo<SuperviseUserVO>> pageQuery(@RequestBody SuperviseUserRequest request) {
        return WebResponse.build(superviseUserService.pageQuery(request));
    }

    @WebAccess(login = true)
    @ApiOperation("列表查询")
    @PostMapping("/listQuery")
    public WebResponse<List<SuperviseUserVO>> listQuery(@RequestBody SuperviseUserRequest request) {
        return WebResponse.build(superviseUserService.listQuery(request));
    }

    @WebAccess(login = true)
    @ApiOperation("新增")
    @PostMapping("/add")
    public WebResponse<Boolean> add(@Valid @RequestBody SuperviseUserAddRequest request) {
        return WebResponse.build(superviseUserService.add(request));
    }

    @WebAccess(login = true)
    @ApiOperation("修改")
    @PostMapping("/update")
    public WebResponse<Boolean> updateByKey(@Valid @RequestBody SuperviseUserUpdateRequest request) {
        return WebResponse.build(superviseUserService.updateByKey(request));
    }

    @WebAccess(login = true)
    @ApiOperation("删除")
    @PostMapping("/delete/{id}")
    public WebResponse<Boolean> deleteByKey(@PathVariable("id") long id) {
        return WebResponse.build(superviseUserService.deleteByKey(id));
    }
}
